package com.lch.base.http.transformer;

import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;
import com.lch.base.http.annotation.APIHeader;
import com.lch.base.http.annotation.APIToken;

import java.lang.annotation.Annotation;
import java.util.Collection;

/**
 * Created by cheukho.chen on 16/8/17.
 * Gson忽略处理策略
 */
public class IgnoreStrategy implements ExclusionStrategy {
    @Override
    public boolean shouldSkipField(FieldAttributes f) {
        Collection<Annotation> annotations = f.getAnnotations();
        for( Annotation annotation : annotations){
            if(annotation.annotationType() == APIToken.class || annotation.annotationType() == APIHeader.class){
                return true;
            }
        }
        return false;
    }

    @Override
    public boolean shouldSkipClass(Class<?> clazz) {
        return false;
    }
}
